#include "settime.h"
#include "ui_settime.h"
#include <QProcess>

SetTime::SetTime(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::SetTime)
{
    ui->setupUi(this);
    QDateTime initialTime(QDate(2024, 10, 15), QTime(21, 20, 0));
    ui->dateTimeEdit->setDateTime(initialTime);
    connect(&timer, SIGNAL(timeout()), this, SLOT(slt_timeout()));
    timer.start(1000);

}

SetTime::~SetTime()
{
    delete ui;
}

void SetTime::slt_timeout()
{
    QDateTime dateTime = QDateTime::currentDateTime();
    ui->showCurrentLabel->setText(dateTime.toString("yyyy/MM/dd hh:mm:ss"));

}
void SetTime::on_pushButton_clicked ()
{
    QDateTime dateTime = ui->dateTimeEdit->dateTime();
    time_t tt = (time_t)dateTime.toTime_t();
    stime(&tt);


    QProcess proc;
    proc.start("hwclock -w");
    if (proc.waitForFinished(3000))
        {
         qDebug("set rtc success...");
    }

}

void SetTime::on_godata_clicked()
{
    emit goback();
}
